﻿/*
Description:机加流水卡批量打印
Copyright (c) : 通力凯顿（北京）系统集成有限公司
Writer:zhangrj
create Date:
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Camstar.Collections;
using BusinessRule.Business;
using System.Data;
using BusinessRule.Common;

public partial class forms_Custom_Print_ContainerMachiningPrintForm : System.Web.UI.Page
{
    public string strHtml;//页面html
    public YPContainerBusiness ypBusiness = new YPContainerBusiness();
    public YPCommonBusiness common = new YPCommonBusiness();
    public List<Dictionary<string, object>> printSession;
    public DataTable dtMain;//批次基本信息
    public DataTable dtcontainerAttribute;//批次属性
    public DataTable dtContainerStep;//工序信息
    public DataTable dtSpecResource;//设备型号
    public DataTable dtSpecCheckPoints;//关键过程控制记录
    public DataTable dtchildContainer;//子批次信息
    public DataTable dtContainerStepAttributes;//批次工序属性信息 add zhunan 2022.1.19
    //public DataTable dtContainerStepCheckNotes;//批次工序检验备注信息
    public DataTable dtContainerSubInfo;//批次的子批次信息
    public DataTable dtIssue;//批次集件信息
    int totalHeight = 1000;//一页的高度(工序)
    int rowHeight = 76;//起始行高，内容表头的（工序）
    public int pages = 0;//全局页码
    //系统根路径
    string path = "";
    public bool isBank = false;//是否空白
    public bool checkerNoEdit = true;
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            if (!IsPostBack)
            {
                path = Request.Url.AbsoluteUri.ToString().Substring(0, Request.Url.AbsoluteUri.IndexOf("forms")) + "ImageTemp/";
                strHtml = string.Empty;
                printSession = (List<Dictionary<string, object>>)Session["PrintInfo"];
                Session.Remove("PrintInfo");
                if (printSession != null && printSession.Count > 0)
                {
                    for (int i = 0; i < printSession.Count; i++)
                    {
                        rowHeight = 76;//起始行高，内容表头的（工序）
                        pages = 0;//全局页码
                        isBank = false;//是否空白                       
                        strHtml += InitData(printSession[i], i + 1 == printSession.Count ? true : false);
                    }
                }
                else
                {
                    string ContainerId = Request["ContainerId"];
                    string WorkflowId = Request["WorkflowId"];
                    string IsBlank = Request["IsBlank"];
                    if (string.IsNullOrEmpty(ContainerId) || string.IsNullOrEmpty(WorkflowId) || string.IsNullOrEmpty(IsBlank))
                    {
                        ClientScript.RegisterStartupScript(ClientScript.GetType(), "myScript", "<script>alert('刷新无效，请关闭后重新打印');</script>");
                        return;
                    }
                    Dictionary<string, object> printInfo = new Dictionary<string, object>();
                    printInfo["ContainerId"] = ContainerId;
                    printInfo["WorkflowId"] = WorkflowId;
                    printInfo["IsBlank"] = Boolean.Parse(IsBlank);
                    strHtml += InitData(printInfo, true);
                }
            }
        }
        catch (Exception ex)
        {
            Response.Write("<script type='text/javascript'>alert('系统报错：" + ex.Message + "');window.close();</script>");
        }
    }
    /// <summary>
    /// 初始化打印页面
    /// </summary>
    /// <param name="printInfo">打印信息</param>
    /// <param name="isLastContainer">是否最后一个批次</param>
    /// <returns></returns>
    private string InitData(Dictionary<string, object> printInfo, bool isLastContainer)
    {
        isBank = bool.Parse(printInfo["IsBlank"].ToString());
        var DP = ypBusiness.GetContainerPrintInfo(printInfo);
        dtMain = DP.Tables["dtMain"];//批次主信息
        dtcontainerAttribute = DP.Tables["containerAttributeDt"];//批次属性
        dtContainerStep = DP.Tables["dtContainerStep"];//批次工序列表
        dtSpecResource = DP.Tables["specResource"];//设备型号
        dtSpecCheckPoints = DP.Tables["dtCheckItemList"];//关键过程控制记录
        dtchildContainer = DP.Tables["childContainer"];//子批次信息
        dtContainerStepAttributes = DP.Tables["dtContainerStepAttributes"];//批次工序属性信息 add zhunan 2022.1.19
        //dtContainerStepCheckNotes = DP.Tables["dtContainerStepCheckNotes"];//批次工序检验备注信息
        dtContainerSubInfo = DP.Tables["dtContainerSubInfo"];//批次的子工艺批次信息
        dtIssue = DP.Tables["dtIssue"];//批次集件信息
        //关键过程序多人报工时，只在最后一行显示关键过程信息
        #region 同一工序多条报工记录处理
        //checkerNoEdit: 检验员没有录入过实测值
        if (dtSpecCheckPoints.Rows.Count > 0)
        {
            checkerNoEdit = dtSpecCheckPoints.Select("containerstepworkreportid IS NOT NULL").Length == 0 ? true : false;
        }

        dtContainerStep = common.MergeContainerStepWorkReport(dtContainerStep, checkerNoEdit);
        #endregion

        string strCurrHtml = string.Empty;
        strCurrHtml = BindCover();//绑定封面    
        if (dtchildContainer.Rows.Count > 0) 
        {
            strCurrHtml += BindQualityRecord();//绑定质量记录卡
        }
        strCurrHtml += BindQualityProcedure();//绑定质量工序 
        strCurrHtml = strCurrHtml.Replace("=TPages=", pages.ToString());
        if (pages % 2 != 0 && !isLastContainer) //如果页面为基数且不是最后一个批次
        {
            strCurrHtml += GetPaging() + GetPaging();
        }
        else
        {
            strCurrHtml += GetPaging();
        }
        //暂时不做
        //strCurrHtml += BindPatrolCheck();//绑定巡检   
        //strCurrHtml += BindFinalProduct();//绑定成品检验原始记录 
        return strCurrHtml;
    }

    #region 封面
    /// <summary>
    /// 初始化封面
    /// </summary>
    /// <returns></returns>
    private string BindCover()
    {
        DataRow drMain = dtMain.Rows[0];
        string strCover = string.Empty;
        string process_No = drMain["Process_No"].ToString();//工艺规程编号
        if (process_No.Contains("CZ"))
        {
            process_No = process_No.Replace("CZ", "");
        }
        strCover += GetPageHead();//获取页眉
        //获取封面表格
        strCover += GetCoverTable(
            drMain["Part_RevID"].ToString(), //设计图版次
            drMain["ly2sequence"].ToString(), //工艺规程版次
            process_No,//工艺规程编号
            drMain["mfgordername"].ToString(), //生产订单号
            dtIssue.Rows.Count > 0 ? dtIssue.Rows[0]["productbatchno"].ToString() : "", //热处理熔炉号
            drMain["productname"].ToString(), //零件图号
            drMain["YpContainerNo"].ToString(), //批次编号
            drMain["originalqty"].ToString());//数量
        strCover += GetBarCode(drMain["containerid"].ToString(), drMain["mfgordername"].ToString());//获取条形码（订单号，批次ID）
        strCover += GetPaging();//分页
        return strCover;
    }

    /// <summary>
    /// 获取封面表格内容
    /// </summary>
    /// <param name="partRev">设计图版次</param>
    /// <param name="prosseRev">工艺规程版次</param>
    /// <param name="prosseNum">工艺规程编号</param>
    /// <param name="orderNo">生产订单号</param>
    /// <param name="heatDealNo">热处理熔炉号</param>
    /// <param name="partDaringNo">零件图号</param>
    /// <param name="batchNo">批次编号</param>
    /// <param name="qty">数量</param>
    /// <returns></returns>
    private string GetCoverTable(string partRev, string prosseRev, string prosseNum, string orderNo, string heatDealNo, string partDaringNo, string batchNo, string qty)
    {
        DataRow drMain = dtMain.Rows[0];
        string charactertype = drMain["charactertype"].ToString().Trim();
        string strHtml = string.Format(@"<table class='coverTable'>
                           <tr><td colspan='2' style='height:50px;'><span class='coverImportFile'>{0}</span></td></tr>", charactertype == "重要件" || charactertype == "关键件" ? charactertype : "");
        strHtml += "<tr><td colspan='2' style='height:250px;text-align:center;'><span class='coverTitle'>流水作业卡</span><br /><div class='underLine' style='width: 325px; margin-left: 170px'></div></td></tr>";
        strHtml += string.Format(@"<tr><td class='coverTdTitle'><label class='coverLable'>{0}</label>{1}"
                   , GetCoverTableLable("设计图版次", 10), GetCoverTableData(partRev));
        strHtml += string.Format(@"<tr><td class='coverTdTitle'><label class='coverLable'>{0}</label>{1}"
                  , GetCoverTableLable("工艺规程版次", 4.4), GetCoverTableData(prosseRev));
        strHtml += string.Format(@"<tr><td class='coverTdTitle'><label class='coverLable'>{0}</label>{1}"
                  , GetCoverTableLable("工艺规程编号", 4.4), GetCoverTableData(prosseNum));
        strHtml += string.Format(@"<tr><td class='coverTdTitle'><label class='coverLable'>{0}</label>{1}"
                  , GetCoverTableLable("生产订单号", 9.7), GetCoverTableData(orderNo));
        strHtml += string.Format(@"<tr><td class='coverTdTitle'><label class='coverLable'>{0}</label>{1}"
                  , GetCoverTableLable("热处理熔炉号", 4.2), GetCoverTableData(heatDealNo));
        strHtml += string.Format(@"<tr><td class='coverTdTitle'><label class='coverLable'>{0}</label>{1}"
                  , GetCoverTableLable("零件图号", 19), GetCoverTableData(partDaringNo));
        strHtml += string.Format(@"<tr><td class='coverTdTitle'><label class='coverLable'>{0}</label>{1}"
                  , GetCoverTableLable("批次编号", 19), GetCoverTableData(batchNo));
        strHtml += string.Format(@"<tr><td class='coverTdTitle'><label class='coverLable'>{0}</label>{1}"
                  , GetCoverTableLable("数量", 94), GetCoverTableData(qty));
        strHtml += string.Format(@"<tr><td colspan='2'></td></tr></table>
                     <table class='coverTable_Sub'><tr><td style='width: 150px'>备<br /><br />注<br /><br />栏</td><td>{0}</td></tr></table>", drMain["containercomments"]);
        return strHtml;
    }
    /// <summary>
    /// 获取封面数据（GetCoverTable方法的扩展方法）
    /// </summary>
    /// <param name="value"></param>
    /// <returns></returns>
    private string GetCoverTableData(string value)
    {
        return string.Format(@"<span class='coverSign'>:&nbsp;</span></td>
                  <td class='coverTdContent'><div class='coverContent'>{0}</div><div class='underLine'></div></td>
                  </tr>", value);
    }
    /// <summary>
    /// 获取封面字段名
    /// </summary>
    /// <param name="str"></param>
    /// <param name="index"></param>
    /// <returns></returns>
    private string GetCoverTableLable(string str, double index)
    {
        string strHtml = str[0].ToString();
        for (int i = 1; i < str.Length; i++)
        {
            strHtml += string.Format("<span style='margin-left:{0}px;'>{1}</span>", index, str[i].ToString());
        }
        return strHtml;
    }
    /// <summary>
    /// 获取条形码
    /// </summary>
    /// <param name="containId">流水号</param>
    /// <param name="mfgordername">订单号</param>
    /// <returns></returns>
    private string GetBarCode(string containId, string mfgordername)
    {
        if (string.IsNullOrWhiteSpace(mfgordername))
        {
            return string.Format("<div style='height:70px;'><div class=barCode style='float:Right'>*{0}*</div> <div style='clear:both'></div></div>", containId);
        }
        return string.Format("<div style='height:70px;'><div class=barCode style='float:left'>*{0}*</div><div class=barCode style='float:Right'>*{1}*</div></div>", containId, mfgordername);
    }
    #endregion

    #region 质量记录卡
    /// <summary>
    /// 绑定质量记录卡
    /// </summary>
    /// <returns></returns>
    private string BindQualityRecord()
    {
        string strQuality = string.Empty;
        strQuality += "<div style='font-size: 25px;margin-top:5px'>质量记录卡</div>";
        strQuality += GetPageHead();//页眉
        strQuality += GetQualityTable();//表格数据
        strQuality += GetPaging();//分页
        return strQuality;
    }
    /// <summary>
    /// 获取内容表格
    /// </summary>
    /// <returns></returns>
    private string GetQualityTable()
    {
        DataRow dr = dtMain.Rows[0];
        int qualityCount = dtchildContainer.Rows.Count;//子序号总数
        int totalPages = (qualityCount / 61) + 1;//总页数
        int outNum = 0;
        if (dtchildContainer.AsEnumerable().Where(p => int.TryParse(p["childContainerNo"].ToString(), out outNum) == false).Count() == 0) //判断子序号是否为数字
        {
            dtchildContainer = dtchildContainer.AsEnumerable().OrderBy(p => int.Parse(p["childContainerNo"].ToString())).CopyToDataTable();//排序
        }
        int pageSize = 20;//每页行数
        int firCol = 1;//第一列起始数
        int secCol = 21;//第二列起始数
        int thrCol = 41;//第三列起始数
        string strTable = string.Empty;
        string originalstartdate = dr["originalstartdate"].ToString();
        if (!string.IsNullOrWhiteSpace(originalstartdate))
        {
            originalstartdate = DateTime.Parse(originalstartdate).ToString("yyyy年MM月dd日");
        }
        strTable = string.Format(@"<table class='qualityTitleTable'>
                   <tr><td>器材编号</td><td>{0}</td><td>库存地点</td><td>{5}</td></tr>
                   <tr><td>材料牌号</td><td style='width: 250px'>{1}</td><td>建卡日期</td><td style='width: 250px'>{2}</td></tr>
                   <tr><td>计划员</td><td>{3}</td><td>检验员</td><td>{4}</td></tr></table>",
                   dtIssue.Rows.Count > 0 ? dtIssue.Rows[0]["attributevalue"].ToString() : "", //器材编号
                   dr["Materialtrademark"].ToString(), //材料牌号
                   originalstartdate,//建卡日期
                   dr["startemployeeName"].ToString(), //计划员（取值开卡员）
                   dr["checkconfirmempName"].ToString(), //检验员
                   dr["lgort"].ToString()); //库存地点
        for (int i = 0; i < totalPages; i++)
        {
            if (i != 0) { strTable += GetPageHead(); }
            //表头
            strTable += @"<table class='qualityContentTable'>
                        <tr><td>序号</td><td style='width: 180px'>报废工序</td>
                            <td>序号</td><td style='width: 180px'>报废工序</td>
                            <td>序号</td><td style='width: 180px'>报废工序</td></tr>";
            //内容
            for (int j = 0; j < pageSize; j++)
            {
                strTable += "<tr>";
                strTable += firCol <= qualityCount ? string.Format("<td>{0}</td><td>{1}</td>", dtchildContainer.Rows[firCol - 1]["childContainerNo"].ToString().PadLeft(2, '0'), dtchildContainer.Rows[firCol - 1]["workflowstepname"].ToString()) : "<td></td><td></td>";
                strTable += secCol <= qualityCount ? string.Format("<td>{0}</td><td>{1}</td>", dtchildContainer.Rows[secCol - 1]["childContainerNo"].ToString().PadLeft(2, '0'), dtchildContainer.Rows[secCol - 1]["workflowstepname"].ToString()) : "<td></td><td></td>";
                strTable += thrCol <= qualityCount ? string.Format("<td>{0}</td><td>{1}</td>", dtchildContainer.Rows[thrCol - 1]["childContainerNo"].ToString().PadLeft(2, '0'), dtchildContainer.Rows[thrCol - 1]["workflowstepname"].ToString()) : "<td></td><td></td>";
                strTable += "</tr>";
                firCol++;
                secCol++;
                thrCol++;
            }
            firCol += 41;
            secCol += 41;
            thrCol += 41;
            strTable += "</table>";
            strTable += i + 1 != totalPages ? GetPaging() : "";//结束一页并分页
        }
        strTable += "<table class='qualityContentTable' style='margin-top:10px'><tr><td style='width: 150px; height: 100px; font-size: 20px'>废品通知单号</td><td></td></tr></table>";
        return strTable;
    }
    #endregion

    #region 质量工序
    /// <summary>
    /// 绑定质量工序
    /// </summary>
    /// <returns></returns>
    private string BindQualityProcedure()
    {
        string strProcedure = string.Empty;
        strProcedure += GetProcedureTable();//表格数据
        //strProcedure += GetPaging();//分页
        return strProcedure;
    }
    /// <summary>
    /// 获取质量工序内容表格
    /// </summary>
    /// <returns></returns>
    private string GetProcedureTable()
    {
        int containerStepCount = dtContainerStep.Rows.Count;//总的工序行数   
        string strTable = string.Empty;
        strTable += GetPageHead();//页眉
        strTable += GetProcedureTableTitle();
        //开始填充内容
        for (int i = 0; i < containerStepCount; i++)
        {
            DataRow dr = dtContainerStep.Rows[i];
            var isPages = IsPageing(dr);
            if (isPages.Item1)
            {
                strTable += isPages.Item2;
                strTable += "</table>";
                strTable += GetPaging();
                strTable += GetPageHead();
                strTable += GetProcedureTableTitle();
            }
            if (dr["isSpotCheck"].ToString() == "1")//如果是关键工序
            {
                //strTable = GetRowSpan(strTable);//将之前的合并单元格
                strTable += GetProcedureTableContent(dr);//获取工序
                strTable += "</table>";
                strTable += common.SetSpecKeyQualityControl(dr["specid"].ToString(), dr["reportid"].ToString(), checkerNoEdit, dtSpecCheckPoints, dtSpecResource, dr);
                //strTable += SetSpecKeyQualityControl(dr["specid"].ToString(), dr["reportid"].ToString(), checkerNoEdit);//获取关键工序html代码
                strTable += "<table class='qualityContentTable2'>";//更改表头样式
                //strTable += GetProcedureTableTitle(true);//获取隐藏的表头
            }
            else//不是关键工序，则插入工序即可
            {
                strTable += GetProcedureTableContent(dr);
                rowHeight += 31;
            }
        }
        //数据结束后，如果没有布满一页，则补空行
        for (int h = rowHeight + 31; h < totalHeight; h += 31)
        {
            strTable += "<tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>";
        }
        strTable += "</table>";
        return strTable;
    }

    #region 工序方法扩展
    /// <summary>
    /// 获取空白行
    /// </summary>
    /// <returns></returns>
    private string GetBlankRow()
    {
        string strh = string.Empty;
        for (int h = rowHeight + 31; h < totalHeight; h += 31)
        {
            strh += "<tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>";
        }
        return strh;
    }
    /// <summary>
    /// 是否需要分页
    /// </summary>
    /// <param name="dr"></param>
    /// <returns></returns>
    private Tuple<bool, string> IsPageing(DataRow dr)
    {
        string strBlank = string.Empty;
        if (rowHeight + 31 > totalHeight)//如果添加当前行高度后超过最大高度，则换页
        {
            strBlank = GetBlankRow();
            rowHeight = 76;
            return new Tuple<bool, string>(true, strBlank);
        }
        if (dr["isSpotCheck"].ToString() == "1")
        {
            int processCount, designCount;
            if (checkerNoEdit)
            {
                processCount = dtSpecCheckPoints.Select(String.Format("specid='{0}' and checktype = '3'", dr["specid"].ToString())).Length;
                designCount = dtSpecCheckPoints.Select(String.Format("specid='{0}' and checktype = '4'", dr["specid"].ToString())).Length;
            }
            else
            {
                processCount = dtSpecCheckPoints.Select(String.Format("specid='{0}' and checktype = '3' and containerstepworkreportid = '{1}'",
                    dr["specid"].ToString(), dr["reportid"].ToString())).Length;
                designCount = dtSpecCheckPoints.Select(String.Format("specid='{0}' and checktype = '4' and containerstepworkreportid = '{1}'",
                    dr["specid"].ToString(), dr["reportid"].ToString())).Length;
            }

            processCount = processCount == 0 ? 1 : processCount;
            designCount = designCount == 0 ? 1 : designCount;

            //212 = 工序行31px + 关键过程控制记录表头31px + 设备型号及编号90px + 设计参数首行30px + 过程参数首行30px
            if ((rowHeight + 212 + (30 * (processCount + designCount))) > totalHeight)
            {
                strBlank = GetBlankRow();
                rowHeight = 76 + 212 + (30 * (processCount + designCount));
                return new Tuple<bool, string>(true, strBlank);
            }
            rowHeight += 212 + (30 * (processCount + designCount));
        }
        return new Tuple<bool, string>(false, "");
    }
    /// <summary>
    /// 合并单元格
    /// </summary>
    /// <param name="html"></param>
    /// <returns></returns>
    private string GetRowSpan(string html)
    {
        //if (rowspan == 1)
        //    html = html.Replace("=rowmark=", "");
        //else
        //    html = html.Replace("=rowmark=", String.Format(" rowspan='{0}'", rowspan));
        return html;
    }
    /// <summary>
    /// 获取工序表头
    /// </summary>
    /// <returns></returns>
    private string GetProcedureTableTitle()
    {
        return @"<table class='qualityContentTable'><tr><td rowspan='2' style='width:30px;'>工序号</td><td rowspan='2' style='width:150px'>工序名称</td><td rowspan='2' style='width:30px'>数量</td>
                    <td rowspan='2' style='width:50px'>操作者</td><td rowspan='2' style='width:100px'>日期</td><td colspan='4'>检验结果</td>
                    <td rowspan='2' style='width:70px'>首件批次号</td><td rowspan='2' style='width:50px'>检验印</td><td rowspan='2' style='width:100px'>备注</td></tr>
                    <tr><td style='width:30px'>合格</td><td style='width:30px'>报废</td><td style='width:30px'>返修</td><td style='width:30px'>超差</td></tr>";
    }
    /// <summary>
    /// 获取工序
    /// </summary>
    /// <param name="dr"></param>
    /// <returns></returns>
    private string GetProcedureTableContent(DataRow dr)
    {
        string containerId = dtMain.Rows[0]["containerId"].ToString();
        string strContent = "<tr>";
        string specno = dr["isSpotCheck"].ToString() == "1" ? "G" : "";//如果是关键工序，则在工序号前加G
        specno += dr["specno"].ToString();
        strContent += string.Format(@"<td style='width:30px'>{0}</td>", specno);//工序号
        strContent += string.Format(@"<td style='width:150px'>{0}</td>", dr["opdesc"].ToString());//工序名          
        strContent += string.Format(@"<td style='width:30px'>{0}</td>", isBank ? "" : dr["ReportQty"].ToString());//数量
        string reportEmployeeName = string.Empty;//操作员
        string checkemployeeName = string.Empty;//检验员
        string firstcheckcontainerno = string.Empty;//首件批次号
        string reportDate = string.Empty;//日期
        string notes = "";//备注
        if (!isBank)
        {
            //如果是检验序或者是外委序，则显示横线，否则显示操作者
            reportEmployeeName = dr["lastcheck"].ToString() == "1" || dr["controlcode"].ToString() == "LY05"
                ? "<div class='underLine' style='width: 30px;margin-left:10px'></div>" : dr["ReportEmployeeName"].ToString();
            //如果是外委序，则显示横线，否则显示检验员
            checkemployeeName = dr["controlcode"].ToString() == "LY05"
                ? "<div class='underLine' style='width: 30px;margin-left:10px'></div>" : dr["checkemployeename"].ToString();
            reportDate = !string.IsNullOrWhiteSpace(dr["reportdate"].ToString())
                ? DateTime.Parse(dr["reportdate"].ToString()).ToString("yyyy/MM/dd") : "";
            //如果报工了但没有首件批次号，则显示横线
            firstcheckcontainerno = !string.IsNullOrWhiteSpace(dr["ReportQty"].ToString()) && string.IsNullOrWhiteSpace(dr["firstcheckcontainerno"].ToString())
                ? "<div class='underLine' style='width: 50px;margin-left:10px'></div>"
                : dr["firstcheckcontainerno"].ToString().Replace(dtMain.Rows[0]["productname"].ToString() + "/", "");
            // 工序增加显示备注信息 add zhunan 2022.1.19
            if (dtContainerStepAttributes.Rows.Count > 0)
            {
                DataRow[] rows = dtContainerStepAttributes.Select(string.Format("workflowstepid='{0}'", dr["workflowstepid"].ToString()));
                foreach (DataRow item in rows)
                {
                    notes += item["notes"].ToString() + ",";
                }
            }
            //工人备注
            notes += string.IsNullOrWhiteSpace(dr["worknote"].ToString()) ? "" : dr["worknote"].ToString() + ",";
            //检验备注
            notes += string.IsNullOrWhiteSpace(dr["checknote"].ToString()) ? "" : dr["checknote"].ToString() + ",";
            //追加子批次信息
            if (dtContainerSubInfo.Rows.Count > 0)
            {
                DataRow[] rows = dtContainerSubInfo.Select(string.Format("workflowstepid='{0}'", dr["workflowstepid"].ToString()));
                foreach (DataRow item in rows)
                {
                    notes += item["rbtogetherflag"].ToString() + ",";
                }
            }
            ////备注追加工序检验备注信息 
            //if (dtContainerStepCheckNotes.Rows.Count > 0)
            //{
            //    DataRow[] rows = dtContainerStepCheckNotes.Select(string.Format("workflowstepid='{0}'", dr["workflowstepid"].ToString()));
            //    foreach (DataRow item in rows)
            //    {
            //        notes += item["checknote"].ToString() + ",";
            //    }
            //}
            if (dr["controlcode"].ToString() == "LY05" || dr["ISCOMMISSION"].ToString() == "1")//如果是外委
            {
                notes += "外委加工";
            }
            notes = notes.TrimEnd(',');
        }
        strContent += string.Format(@"<td style='width:50px'>{0}</td>", reportEmployeeName);//操作者
        strContent += string.Format(@"<td style='width:100px'>{0}</td>", reportDate);//日期
        strContent += string.Format(@"<td style='width:30px'>{0}</td>", isBank || dr["passqty"].ToString() == "0" ? "" : dr["passqty"].ToString());//合格数
        strContent += string.Format(@"<td style='width:30px'>{0}</td>", isBank || dr["lossqty"].ToString() == "0" ? "" : dr["lossqty"].ToString());//报废数
        strContent += string.Format(@"<td style='width:30px'>{0}</td>", isBank || dr["reworkqty"].ToString() == "0" ? "" : dr["reworkqty"].ToString());//返修数
        strContent += string.Format(@"<td style='width:30px'>{0}</td>", isBank || dr["defectqty"].ToString() == "0" ? "" : dr["defectqty"].ToString());//超差数
        strContent += string.Format(@"<td style='width:70px'>{0}</td>", firstcheckcontainerno);//首件批次号
        strContent += string.Format(@"<td style='width:50px'>{0}</td>", checkemployeeName);//检验印
        //备注
        if (notes != "" && notes.Length > 11)
        {
            strContent += string.Format(@"<td style='width:100px;font-size:10px;text-align:left;'>{0}</td></tr>", notes);
        }
        else
        {
            strContent += string.Format(@"<td style='width:100px;'>{0}</td></tr>", notes);
        }

        return strContent;
    }
    #endregion

    #endregion

    #region 巡检
    /// <summary>
    /// 绑定巡检表格
    /// </summary>
    /// <returns></returns>
    private string BindPatrolCheck()
    {
        string strPatrol = string.Empty;
        strPatrol += GetPageHead();//页眉
        strPatrol += GetPatrolTable();//表格数据
        strPatrol += GetPaging();//分页
        return strPatrol;
    }
    /// <summary>
    /// 获取巡检内容表格
    /// </summary>
    /// <returns></returns>
    private string GetPatrolTable()
    {
        string strTable = string.Empty;
        strTable = "<table class='patrolCheckTable'>";
        strTable += "<tr><td colspan='5' class='patrolCheckTable title'>" +
                      "<div><div class='patrolUnderLine'></div>" +
                      "<div class='patrolCheckTableTitle'>工序巡检记录</div></div></td></tr>";
        strTable += "<tr class='patrolCheckTable head'>" +
                    "<td>日期</td><td>工序</td><td>巡检数量</td><td>顺序号</td><td>检验员</td></tr>";
        //开始填充内容
        strTable += "<tr><td></td><td></td><td></td><td></td><td></td></tr>";
        strTable += "</table>";
        return strTable;
    }
    #endregion

    #region 成品检验原始记录
    /// <summary>
    /// 绑定成品检验原始记录表格
    /// </summary>
    /// <returns></returns>
    private string BindFinalProduct()
    {
        string strFinalProduct = string.Empty;
        strFinalProduct += GetPageHead();//页眉
        strFinalProduct += GetFinalProductTable();//表格数据
        //strFinalProduct += GetPaging();//分页
        return strFinalProduct;
    }
    /// <summary>
    /// 获取成品检验原始记录内容表格
    /// </summary>
    /// <returns></returns>
    private string GetFinalProductTable()
    {
        string strTable = string.Empty;
        strTable = "<div class='finalProductTableTitle'>成品检验原始记录</div>";
        //第一行表格
        strTable += "<table class='finalProductTable'>";
        strTable += "<tr><td colspan='6' class='finalProductTable head'>成品检验内容记录</td></tr>" +
                    "<tr><td class='finalProductTable headtip serNum'>I:</td>" +
                    "<td class='finalProductTable headtip serLable'>工序号</td>" +
                    "<td style='width: 150px;'>123</td>" +
                    "<td class='finalProductTable headtip serNum'>II:</td>" +
                    "<td class='finalProductTable headtip serLable'>外观检验</td>" +
                    "<td style='width: 150px;'></td></tr></table>";
        //第二行表格表头
        strTable += "<table class='finalProductTable_sub'>" +
                    "<tr><td colspan='6'><div class='subheadtip'>III:尺寸检查检验内容</div></td></tr>" +
                    " <tr><td style='width:30px;'>序号</td><td>图纸要求</td><td>结论</td><td>检验员</td></tr>";
        //第二行表格内容
        strTable += "<tr><td>1</td><td></td><td></td><td></td></tr></table>";
        return strTable;
    }
    #endregion

    #region 通用方法
    /// <summary>
    /// 获取页眉
    /// </summary>
    /// <param name="index"></param>
    /// <returns></returns>
    private string GetPageHead()
    {
        pages++;
        DataRow drMain = dtMain.Rows[0];
        string strLeft = string.Format(@"{0}{1}", drMain["Process_No"].ToString(), string.IsNullOrWhiteSpace(drMain["ly2sequence"].ToString()) ? "" : "&" + drMain["ly2sequence"].ToString());
        string vision = "01";//版本
        if (!string.IsNullOrWhiteSpace(drMain["workflowrevision"].ToString()))//如果工艺版本不为空，则选择该版本
        {
            try
            {
                vision = int.Parse(drMain["workflowrevision"].ToString()) < 9 ? "0" + drMain["workflowrevision"].ToString() : drMain["workflowrevision"].ToString();
            }
            catch { }
        }
        else
        {
            if (!string.IsNullOrWhiteSpace(drMain["productrevision"].ToString()))//如果工艺版本为空，产品版本不为空，则选择该版本
            {
                try
                {
                    vision = int.Parse(drMain["productrevision"].ToString()) < 9 ? "0" + drMain["productrevision"].ToString() : drMain["productrevision"].ToString();
                }
                catch { }
            }
        }
        string strRight = string.Format("{0}-LK-{1}/=TPages=-V{2}", drMain["productname"].ToString(), pages, vision);
        return String.Format("<table class='headTable'><tr><td style='text-align: left'>{0}</td><td style='text-align: right'>{1}</td></tr></table>", strLeft, strRight);
    }
    /// <summary>
    /// 获取分页
    /// </summary>
    /// <returns></returns>
    private string GetPaging()
    {
        return "<div class='paging'></div>";
    }
    #endregion

}